/*
 * @Author: daniel_du dll_2018@126.com
 * @Date: 2022-05-08 12:50:36
 * @LastEditors: daniel_du dll_2018@126.com
 * @LastEditTime: 2022-05-09 16:42:59
 * @FilePath: /safe_transmission_platform/src/mysqldb.h
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#ifndef __MYSQLDB_H__
#define __MYSQLDB_H__

#include <mysql/mysql.h>
#include <string>
#include <cstring>
#include <memory>
#include <cstdint>
#include "macro.h"
#include <vector>
#include <mutex>

namespace daniel
{
    struct MysqlInfo
    {
        MysqlInfo():m_host("127.0.0.1"),m_user("root"),m_pwd(""),m_database(""),m_port(0)
        {}
        MysqlInfo(const std::string& host, const std::string user, const std::string& pwd, const std::string& database,const uint32_t& port):m_host(host),m_user(user),m_pwd(pwd),m_database(database),m_port(port)
        {}
        std::string m_host;
        std::string m_user;
        std::string m_pwd;
        std::string m_database;
        uint32_t m_port;
    };
    class MysqlDB
    {
    public:
        using ptr=std::shared_ptr<MysqlDB>;
        using queryResult=std::vector<std::vector<std::string>>;
        MysqlDB(const MysqlInfo& info);
        ~MysqlDB();
        MysqlInfo getMysqlInfo() { return m_info;}
        void setMysqlInfo(const MysqlInfo& info) {m_info=info; }
        bool connectToDB();
        queryResult excuteQuery(const std::string& query);
        bool excuteDML(const std::string& query);
        static void PrintResult(const queryResult& result);
        
    private:
        MysqlDB(const MysqlDB&)=delete;
        MysqlDB operator=(const MysqlDB&)=delete;
    private:
        MysqlInfo m_info;
        MYSQL* m_connectSql;
    };
}

#endif
